/**
 * 功能描述
 */

define(function (require, exports, module) {
	var Grid = require("grid");
	
	
	var map = ["dayOne","dayTwo","dayThree","dayFour","dayFive","daySix","daySeven","dayEight","dayNine","dayTen","dayEleven","dayTwelve","dayThirdteen","dayFourteen","dayFifteen"];
	
    var instance = {
        initComponent: function (params,widget) {
        	var columns = [{
    			name:"roomtypename",
				label:"房型",
    		},{
    			name:"roomcount",
				label:"总房数",
    		}];
        	
        	//var curDate = new Date().getTime();
        	
        	var startDate = widget.get("subnav").getValue("visitDate").start;
        	var endDate = widget.get("subnav").getValue("visitDate").end;
        	
        	
        	var visitDays=((endDate+1)-startDate)/1000/60/60/24;
        	console.log(visitDays);
        	
        	if(visitDays <= 15){
        		for(var i=0;i < visitDays;i++){
        			var select ;
                	
                	if(moment(startDate).add(i,"days").format("d")==0){
                		select ="日"
        			}else if(moment(startDate).add(i,"days").format("d")==1){
        				select = "一"
        			}else if(moment(startDate).add(i,"days").format("d")==2){
        				select = "二"
        			}else if(moment(startDate).add(i,"days").format("d")==3){
        				select = "三"
        			}else if(moment(startDate).add(i,"days").format("d")==4){
        				select = "四"
        			}else if(moment(startDate).add(i,"days").format("d")==5){
        				select = "五"
        			}else if(moment(startDate).add(i,"days").format("d")==6){
        				select = "六"
            	    }
        		
            		columns.push({
            			name: map[i],
            			label: moment(startDate).add(i,"days").format("MM.DD") + "/周" +select 
            		})
            	}
        	}else{
        		for(var i=0;i < 15;i++){
            		columns.push({
            			name: map[i],
            			label: moment(startDate).add(i,"days").format("MM.DD") + "/周" +select 
            		})
            		
        		
        		}
        	}
        	
        	var grid = new Grid({
        		parentNode:".J-grid",
        		autoRender:false,
        		model : {
        			url : "api/roomstatistics/queryallbydate",
            		params : function(){
            			var subnav = widget.get("subnav");
            			return {
            				"pkServicePoint": subnav.getValue("servicepoint"),
            				"startDate": widget.get("subnav").getValue("visitDate").start,
							"endDate": widget.get("subnav").getValue("visitDate").end,
        					fetchProperties:"roomtypename," 
        							+ "roomcount,"
        							+ "dayOne,"
        							+ "dayTwo,"
        							+ "dayThree,"
        							+ "dayFour,"
        							+ "dayFive,"
        							+ "daySix,"
        							+ "daySeven,"
        							+ "dayEight,"
        							+ "dayNine,"
        							+ "dayTen,"
        							+ "dayEleven,"
        							+ "dayTwelve,"
        							+ "dayThirdteen,"
        							+ "dayFourteen,"
        							+ "dayFifteen,"
        							
        						}
        		},
        		columns : columns
        	   } 
        	});
        	//$(".J-grid-footer").hide();
        	widget.set("grid",grid);
        }
    };
    module.exports = instance;
});
